package com.tanger.im.service.members;

import com.tanger.common.exception.AbstractController;
import com.tanger.common.result.ActionResult;
import com.tanger.common.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 用户控制层
 * @Author Hchenbin
 * @Date 2023/12/26 15:13
 * @Version 1.0
 */
@RestController
@RequestMapping("/tanger/api/im/user:group-members/{groupId}")
@Api(value = "IM:IM用户群/组:成员",tags="IM:IM用户群/组:成员")
public class IMUserGroupMembersController extends AbstractController{

    @Autowired
    private IMUserGroupMembersService service;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "组群ID", required = true, paramType = "path", dataType = "Long"),
            @ApiImplicitParam(name = "userId", value = "IM用户ID", required = true, paramType = "query", dataType = "Long")})
    @ApiOperation(value = "退出组群")
    @DeleteMapping("/exit")
    public ActionResult exit(@PathVariable Long groupId,@RequestParam Long userId) {
        if (StringUtil.isNull(groupId) || StringUtil.isNull(userId)) {
            return ActionResult.buildResultError("参数缺失");
        }
        return service.exit(groupId, userId);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "组群ID", required = true, paramType = "path", dataType = "Long"),
            @ApiImplicitParam(name = "userId", value = "IM用户ID", required = true, paramType = "query", dataType = "Long")})
    @ApiOperation(value = "转让组群")
    @PostMapping("/transfer")
    public ActionResult transfer(@PathVariable Long groupId,@RequestParam Long userId) {
        if (StringUtil.isNull(groupId) || StringUtil.isNull(userId)) {
            return ActionResult.buildResultError("参数缺失");
        }
        return service.transfer(groupId, userId);
    }

    @ApiImplicitParam(name = "groupId", value = "组群ID", required = true, paramType = "path", dataType = "Long")
    @ApiOperation(value = "删除成员")
    @DeleteMapping("/delete")
    public ActionResult delete(@PathVariable Long groupId,@RequestBody List<Long> userIds) {
        if (StringUtil.isNull(groupId) || CollectionUtils.isEmpty(userIds)) {
            return ActionResult.buildResultError("参数缺失");
        }
        return service.delete(groupId, userIds);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "组群ID", required = true, paramType = "path", dataType = "Long"),
            @ApiImplicitParam(name = "userId", value = "IM用户ID", required = true, paramType = "query", dataType = "Long")})
    @ApiOperation(value = "设置管理员")
    @PatchMapping("/put")
    public ActionResult put(@PathVariable Long groupId,@RequestParam Long userId) {
        if (StringUtil.isNull(groupId) || StringUtil.isNull(userId)) {
            return ActionResult.buildResultError("参数缺失");
        }
        return service.put(groupId, userId);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "组群ID", required = true, paramType = "path", dataType = "Long"),
            @ApiImplicitParam(name = "userId", value = "IM用户ID", required = true, paramType = "query", dataType = "Long")})
    @ApiOperation(value = "设置成员禁言")
    @PatchMapping("/prohibition")
    public ActionResult prohibition(@PathVariable Long groupId,@RequestParam Long userId) {
        if (StringUtil.isNull(groupId) || StringUtil.isNull(userId)) {
            return ActionResult.buildResultError("参数缺失");
        }
        return service.prohibition(groupId, userId);
    }

    @ApiImplicitParam(name = "groupId", value = "组群ID", required = true, paramType = "path", dataType = "Long")
    @ApiOperation(value = "设置全员禁言")
    @PatchMapping("/all:prohibition")
    public ActionResult prohibitionAll(@PathVariable Long groupId) {
        if (StringUtil.isNull(groupId)) {
            return ActionResult.buildResultError("参数缺失");
        }
        return service.prohibitionAll(groupId);
    }
}

